﻿package com.xuanque.mahjongDice.effects 
{
	import flash.display.*;
	import flash.events.*;
	import caurina.transitions.*;
	
	import com.xuanque.mahjongDice.display.GameAreaControl;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> 总共花了10秒时间...)
	 */
	public class TweenEveryItem 
	{
		private var container_mc:DisplayObjectContainer;
		private var newX:Number;
		private var newY:Number;
		
		private var oldX_array:Array;
		private var oldY_array:Array;
		private var _length:uint = 8;
		private var index:uint = 0;
		private var currentIndex:uint = 1;
		
		private var finishFun:Function;
		private var dealWithFun:Function;
		
		public function TweenEveryItem(container:DisplayObjectContainer,X:Number,Y:Number,finishFun:Function = null,dealWithFun:Function = null) 
		{
			this.container_mc = container;
			this.newX = X;
			this.newY = Y;
			
			this.finishFun = finishFun;
			this.dealWithFun = dealWithFun;
			
			init();
			
		}
		
		private function init():void {
			
			this.oldX_array = new Array();
			this.oldY_array = new Array();
			
			var _mc:MovieClip;
			for (var i:uint = 1; i <= _length; i++) {
				
				_mc = container_mc["sice0" + i];
				if (i == _length) {
					//_mc.alpha = 0;
					//_mc.gotoAndStop("isnull");
				}else {
					this.oldX_array.push(_mc.x);
					this.oldY_array.push(_mc.y);
					
					_mc.x = this.newX;
					_mc.y = this.newY;
				}
				
			}
			
			this.TweenIndex(1);
		}
		
		
		/**
		* 加载索引;
		* @param	i
		* @return
		*/
		public function TweenIndex(i:uint):void {
			
			if (this.dealWithFun != null) {
				this.dealWithFun();
			}
				
				
			var twnMc = this.container_mc["sice0" + i];
			var twnMc_scaleX:Number = twnMc.scaleX;
			var twnMc_scaleY:Number = twnMc.scaleY;
			twnMc.visible = true;
			twnMc.alpha = 1;
			twnMc.scaleX = twnMc.scaleY = .5;
			
			Tweener.addTween(twnMc,{scaleX:twnMc_scaleX ,scaleY:twnMc_scaleY , x:this.oldX_array[i-1],y:this.oldY_array[i-1],time:.2,onComplete:this.motionFinish});
		}
		
		
		/**
		* 完成一个后,进入下一个;
		* @param	event
		*/
		private function motionFinish(){
			NextPic();
		}
		
		
		/**
		* 控制操作,下一个;
		* @param	//索引与数组相差一个
		*/
		private function NextPic():void{
			//trace(this.currentIndex)
			this.currentIndex ++;
			if (this.currentIndex > this._length - 1) { //要再减去1
				
				if (this.finishFun != null) {
					this.finishFun();
				}
				
				return;
			}
			this.TweenIndex(this.currentIndex);
			
		}
		
		
		
	}
	
}